package org.springframework.boot.netty.argumentResolver;

import org.springframework.boot.autoconfigure.netty.channel.Channel;
import org.springframework.boot.autoconfigure.netty.enums.StartUpMode;
import org.springframework.boot.netty.converter.MessageConverter;
import org.springframework.boot.netty.exception.ConvertException;
import org.springframework.boot.netty.listener.Message;

import java.util.Collection;

/**
 * Author: huoxingzhi
 * Date: 2020/12/16
 * Email: hxz_798561819@163.com
 */
public class ChannelAwareMethodArgumentResolver extends HandlerMethodArgumentResolverAdapter {

    @Override
    public boolean supportsParameter(Class<?> receiveClass,MethodParameter methodParameter) {
        return Channel.class.isAssignableFrom(methodParameter.getParameter().getType());
    }

    @Override
    public Object resolveArgument(Message message, MethodParameter methodParameter) throws ConvertException {
        Collection<MessageConverter> messageConverters = this.applicationContext.getBeansOfType(MessageConverter.class).values();

        return new Channel(message.getCurrentChannel(), messageConverters);
    }
}
